# http://www.imbi.uni-freiburg.de/parallel/docs/Reisensburg2009_TutParallelComputing_Knaus_Porzelius.pdf
library(snowfall)

sfInit(parallel=TRUE, cpus=8)

sfLibrary(igraph)

s32c <- read.graph(file = "eat-seed32-core-graphml.xml", format = "graphml")
mc <- readRDS("maximal-cliques.rds")
cw <- readRDS("clique-words.rds")

sfExportAll()

lmc <- sapply(mc, length)
lcw <- sapply(cw, length)

minl <- min(unlist(lcw))
maxl <- max(unlist(lcw))

scw <- c()

for (p in c(minl:maxl))
{
	ids <- which(lcw == p)
	scw <- append(scw, cw[ids])
}

saveRDS(scw, "sorted-cliques.rds")

sfStop()

